package com.coin.controller;

import com.coin.service.BalanceTransferService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * Created by chenhao on 2017/5/18.
 */
@RestController
@RequestMapping("/trade")
public class BalanceTransferController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private BalanceTransferService balanceTransferService;

    @GetMapping("/balanceTransfer")
    public ResponseEntity<Long> balanceTransfer(@RequestParam String amount,
                                                @RequestParam Long outMemberId,
                                                @RequestParam Long intMemberId,
                                                @RequestParam Long businessId,
                                                @RequestParam Integer businessType) {
        try {
            long flowId = balanceTransferService.balanceTransfer(new BigDecimal(amount), outMemberId, intMemberId, businessId, businessType);
            return new ResponseEntity<Long>(flowId,HttpStatus.OK);
        } catch (Exception e) {
            logger.error("balanceTransfer :{}", e);
            return new ResponseEntity<Long>(-1L,HttpStatus.INTERNAL_SERVER_ERROR);
        }

    }
}
